<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/admin/inc/tag.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML><HEAD><TITLE>产品选购</TITLE>
<META content="text/html; charset=UTF-8" http-equiv=Content-Type>
<script type="text/javascript" src="/pc/js/setcook.js"></script>
<script type="text/javascript" src="js/jquery-1.7.min.js"></script>
<script type="text/javascript" src="js/base.js"></script>
<LINK rel=stylesheet type=text/css href="/pc/product/css/list.css" media=all></LINK>
<script type="text/javascript">
	function setParam(type, value) {
		value = unescape(value);
		var url = window.location.href.split("?")[0];
		var search = window.location.search;
		var finalParams = "";
		if(search == "") {
			finalParams = "?" + type + "=" + value;
		}else {
			// 如果没有该参数则新增
			if(search.indexOf(type) == -1) {
				finalParams = search + "&" + type + "=" + value; 
			}else {//存在则修改
				// 去掉问号
				var params = search.substring(1, search.length);
				var arr = params.split("&");
				for(var i=0; i<arr.length; i++) {
					if(arr[i].indexOf(type) != -1) {
						if(i == 0) {
							finalParams += "?" + type + "=" + value;
						}else {
							finalParams += "&" + type + "=" + value;
						}
					}else {
						if(i == 0) {
							finalParams += "?" + arr[i];	
						}else {
							finalParams += "&" + arr[i];
						}
					}
				}
			}
		}
		window.location.href = url + finalParams;
	}
	
	// 不限条件
	function cancelParam(type) {
		var url = window.location.href;
		if(url.indexOf(type) == -1) {
		}else { 
			url = url.split("?")[0];
			var search = window.location.search;
			// 去掉问号
			var params = search.substring(1, search.length);
			var arr = params.split("&");
			var finalParams = "";
			var isFirst = true;
			for(var i=0; i<arr.length; i++) {
				if(arr[i].indexOf(type) == -1) {
					if(isFirst) {
						finalParams += arr[i];
						isFirst = false;
					}else {
						finalParams += "&" + arr[i];
					}
				}
			}
			if(finalParams&&finalParams!=""){
				window.location.href=url+"?"+finalParams;
			}else{
				window.location.href=url;
			}
		}
	}
	
	//设置不限的样式
	function setNO() {
		var url = window.location.search;
		if(url.indexOf("config_id") == -1) {
			$("#no_config_id").addClass("cur");
		}
		if(url.indexOf("brand_name") == -1) {
			$("#no_brand_name").addClass("cur");
		}
	}
	
	// 设置选择的条件
	function setParamList() {
		var search = window.location.search;
		if(search == null || search == "") {
			$("#choose_param_list").html("");
		}else {
			// 去掉问号
			var params = search.substring(1, search.length);
			var arr = params.split("&");
			var html = "";
			for(var i=0; i<arr.length; i++) {
				if(arr[i]&&arr[i]!=""){
					var arr1 = arr[i].split("=");
					var key = arr1[0];
					var value = arr1[1];
					if(key == "config_id") {
						value = $("#" + value + "_map").val();
					}
					html+="<SPAN><A class='cur' href='javascript:void(0)' onclick='cancelParam(\"" + key + "\")'"+
							"target='_self'>" + value + "</A></SPAN>";
				}
			}
			$("#choose_param_list").html(html);
		}
	}
	
	$(document).ready(function () {
		setNO();
		// 设置选择的条件
		setParamList();
	});
</script>
<script type="text/javascript">
	function addProduct(product_id,num){
		var trolleyJSON=get_cookie("trolleyJSON");

		var trolleyArray;
		if(trolleyJSON==undefined||trolleyJSON=="undefined"){
			trolleyArray=new Array();
		}else{
			trolleyArray=JSON.parse(trolleyJSON);
		}

		for(var i=trolleyArray.length-1;i>=0;i--){
			if(trolleyArray[i].product_id==product_id)
				break;
		}
		if(i>=0){
			trolleyArray[i].num=trolleyArray[i].num+num;
		}else{
			var product=new Object();
			product.product_id=product_id;
			product.num=num;
			trolleyArray.push(product);
		}

		trolleyJSON=JSON.stringify(trolleyArray);
		setCookie("trolleyJSON",trolleyJSON);
	}
//	addProduct(1,3);
</script>
</HEAD>
<BODY>
<DIV class="wraper clearfix">
	<DIV class=main><!-- 产品搜索 -->
		<DIV class="chooseBox mb10">
			<DIV id=J-getWap class=getWap><!-- 参数选择开始 -->
				<!-- 类型 -->
				<DIV id="config_choose_div" class="getParam getBrand">
					<SPAN>类型：</SPAN>
					<EM id="no_config_id" class="all"><A onclick="cancelParam('config_id')" href="javascript:void(0)" target=_self>不限</A></EM>
					<!-- 类别列表 -->
					<admin:configList name="rows" />
					<c:forEach items="${rows}" var="row">
						<input type="hidden" id="${row.config_id}_map" value="${row.config_name}" /> 
						<c:if test="${row.config_id == param.config_id}">
							<em class="all cur"><a href="javascript:void(0)" target="_self">${row.config_name}</a></em>
						</c:if>
						<c:if test="${row.config_id != param.config_id}">
							<em class="all"><a href="javascript:void(0)" onclick="setParam('config_id', ${row.config_id})" target="_self">${row.config_name}</a></em>
						</c:if>
					</c:forEach>
					<!-- 产品列表 -->
					<admin:productList name="products" typeId="${param.config_id}" brandName="${param.brand_name}" status="1" pageMax="10"/>
					<DIV class=clear></DIV>
				</DIV>
				<!-- 品牌 -->
				<DIV id="brand_choose_div" class="getParam">
					<SPAN>品牌：</SPAN>
					<EM id="no_brand_name" class="all"><A onclick="cancelParam('brand_name')" href="javascript:void(0)" target=_self>不限</A></EM>
					<admin:brandList name="rows1" />
					<c:forEach items="${rows1}" var="row1">
						<c:if test="${row1.product_brand_name == param.brand_name}">
							<em class="all cur"><a href="javascript:void(0)" target="_self">${row1.product_brand_name}</a></em>
						</c:if>
						<c:if test="${row1.product_brand_name != param.brand_name}">
							<em class="all"><a onclick="setParam('brand_name', escape('${row1.product_brand_name}'))"" href="javascript:void(0)" target="_self">${row1.product_brand_name}</a></em>
						</c:if>
					</c:forEach>
					<DIV class=clear></DIV>
				</DIV>
				<DIV class=hadWap>
					<DIV class=hadL><STRONG>已选条件：</STRONG> 
						<DIV class=choose>
							<span id="choose_param_list">
								<%--
								<SPAN><A class=cur href="" target=_self>700-900元<EM></EM></A></SPAN> 
								--%>
							</span>
							<SPAN class=num>[共 <span id="totalProduct">${totalCount}</span> 款产品]</SPAN> 
						</DIV>
					</DIV>
						<DIV class=hadR>
							<A href="/pc/product/product.jsp" target=_self>重新筛选</A>
						</DIV>
					<DIV class=clear></DIV>
				</DIV>
			</DIV>
			<DIV class="product-box mb10">
				<DIV class=content><!-- 产品列表 -->
				<UL id="Jproduct-list" class="product-list">
					<c:forEach items="${products}" var="product">
						<li>
							<div class="hd">
								<p><span class=name>${product.product_name}</span></p>
								<I class=price  style="color: red;">￥<EM>${product.product_price}</EM></A></I> 
							    <DIV class=product-pic><IMG src="${product.product_pic_url}" width=120 height=90 /></DIV>
							</div>
							<DIV class="bd clearfix">
				  				<DL class="param clearfix">
				    				<DD><I class=tit>产品编号：</I>${product.product_no}</DD>
				    				<DD><I class=tit>品牌：</I>${product.product_brand_name}</DD>
				    				<DD><I class=tit>库存：</I>${product.product_stock}</DD><DD></DD>
				    				<DD><I class=tit>说明：</I>${product.product_note}</DD>
				    			</DL>
					  			<DIV class=dRise>
					  				<A href="#" onclick="javascript:addProduct(${product.product_id},1);alert('已成功加入到购物车');return false;" class="blue addLogo">加入购物车</A><BR/>
					  			</DIV>
				  			</DIV>
				  			<DIV class=ft>
				  				<I><A rel=nofollow target=_blank></A></I> 
				  			</DIV>
						</li>
					</c:forEach>
				 </UL>
				</DIV>
			</DIV>
			<DIV class=pconline_page style="padding:10px 0;">
				<a href="/pc/product/trolley.jsp" target="_blank">查看购物车</a>
			</DIV>
		</DIV>
	</DIV>
</DIV>
</BODY>
</HTML>
